/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.application.isradeleon.notifyexample;

import com.application.isradeleon.notify.helper.PixelMapHelper;
import junit.framework.TestCase;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import ohos.app.dispatcher.TaskDispatcher;
import ohos.app.dispatcher.task.TaskPriority;
import ohos.media.image.PixelMap;
import org.junit.Assert;
import org.junit.Test;

/**
 * Notify单元测试
 */
public class NotifyTest extends TestCase {

    @Test
    public void testGetPixelMapFromUrl() {
        String url = "https://images.pexels.com/photos/1058683/pexels-photo-1058683.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940";
        Context appContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        TaskDispatcher urlTask = appContext.createParallelTaskDispatcher("", TaskPriority.DEFAULT);
        urlTask.syncDispatch(() -> {
            PixelMap pixelMap = PixelMapHelper.getPixelMapFromUrl(url);
            Assert.assertNotNull(pixelMap);
        });
    }

    @Test
    public void testGetPixelMapFromResAndCircle() {
        Context appContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        PixelMap pmRes = PixelMapHelper.getPixelMapFromRes(appContext, ResourceTable.Media_ic_small_icon);
        PixelMap pmCircle = PixelMapHelper.toCircleBitmap(pmRes);
        Assert.assertNotNull(pmRes);
        Assert.assertNotNull(pmCircle);
    }

}
